package zee.com.customviewexample.activity

import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.LinearLayout
import com.zee.adapter.SimpleZxBannerAdapter
import com.zee.extendobject.setMargin
import com.zee.log.ZLog
import com.zee.utils.UIUtils
import com.zee.view.ZxBannerView
import com.zee.view.ZxBannerView.OnZxBannerChangeListener
import kotlinx.android.synthetic.main.activity_zx_banner.*
import zee.com.customviewexample.R

class ZxBannerActivity : BaseActivity() {

    override fun getLayoutID(): Int {
        return R.layout.activity_zx_banner
    }

    val list = arrayListOf(R.drawable.banner1, R.drawable.banner2)
    override fun initViews() {
        zv_banner_a.setOnBannerChangeListener(object : OnZxBannerChangeListener {
            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
            }

            override fun onIndicatorsSelected(position: Int) {
                ZLog.i("当前选择" + position)
            }
        })
        onExampleA()
        onExampleB()
    }

    fun onExampleB() {
        zv_banner_b.setBannerAdapter(object : SimpleZxBannerAdapter<Int>(list) {
            override fun initViews(imageView: ImageView, position: Int) {
                val value = getBean();
                imageView.setOnClickListener {
                    UIUtils.showToastShort("当前位置:$position")
                }
                imageView.setImageResource(value)
                imageView.setMargin {
                    leftMargin = 200
                    rightMargin = 200
                }
            }
        })
    }

    fun onExampleA() {
        zv_banner_a.setBannerAdapter(object : SimpleZxBannerAdapter<Int>(list) {
            override fun initViews(imageView: ImageView, position: Int) {
                val value = getBean();
                imageView.setOnClickListener {
                    UIUtils.showToastShort("当前位置:$position")
                }
                imageView.setImageResource(value)
            }
        })
    }


    override fun onPause() {
        super.onPause()
        zv_banner_a.onStopLoop()
    }

    override fun onResume() {
        super.onResume()
        zv_banner_a.onStartLoop()
        ZLog.i("Bannview开始循环")
    }

}
